<template>
  <div class="data">
    <el-form label-width="80px" class="form-item">
      <el-form-item label="用户名">
        <el-input v-model="form.username"></el-input>
      </el-form-item>
      <el-form-item label="密碼">
        <el-input type="password" v-model="form.password"></el-input>
      </el-form-item>
      <el-form-item label="目标院校">
        <el-input v-model="form.tschool"></el-input>
      </el-form-item>
      <el-form-item label="邮箱">
        <el-input v-model="form.email"></el-input>
      </el-form-item>
      <el-form-item label="qq号码">
        <el-input v-model="form.qq"></el-input>
      </el-form-item>
      <el-form-item label="手机号码">
        <el-input v-model="form.telphone"></el-input>
      </el-form-item>
      <el-form-item>
        <el-radio v-model="form.sex" label="男">男</el-radio>
        <el-radio v-model="form.sex" label="女">女</el-radio>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        username: "",
        password: "",
        tschool: "",
        email: "",
        qq: "",
        telphone: "",
        sex: ""
      }
    };
  },
  created: function() {
   // console.log(this.$store.state.id);
    var Id = this.$store.state.id;
    this.$http.get("user/getuser?id=" + Id).then(result => {
      this.form = result.body.data;
    });
  },
  methods: {
    onSubmit() {
      //封装成json格式
      
      var objdata = JSON.stringify(this.form);
      this.$http.post('admin/edituser', objdata).then(result => {
        // console.log(result.body);
        if(result.body.flag==true){
          //弹出登录成功
          this.$message.success(result.body.message);
        } else {
          // 弹出通知框提示登录失败信息
          this.$message.error("修改失败！");
        }
      });
    }
  }
};
</script>

<style>
.data {
  width: 100%;
  height: 100%;
}
.form-item {
  width: 30%;
  margin: auto;
}
</style>